package com.huanwei.mini.adapter;

import android.annotation.SuppressLint;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.huanwei.mini.R;
import com.huanwei.mini.base.MyApplication;
import com.huanwei.mini.http.ML;
import com.huanwei.mini.interfaces.OnItemClickListener2;

import java.util.List;


/**
 * Created by HongJay on 2016/9/13.
 */
public class Recycle_Threeadapter extends RecyclerView.Adapter<Recycle_Threeadapter.OneViewHolder> {


    public Recycle_Threeadapter(List<ML.SdataBean.FirstBean.SecondBean.ThirdBean> ccList ) {
        this.ccList = ccList;

    }


    @Override
    public Recycle_Threeadapter.OneViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.tab_item_2_j, parent, false);
        OneViewHolder viewHolder = new OneViewHolder(view);
        return viewHolder;


    }

    List<ML.SdataBean.FirstBean.SecondBean.ThirdBean> ccList;


    private OnItemClickListener2 mOnItemClickListener;//声明接口

    public void setOnItemClickListener(OnItemClickListener2 onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }


    @SuppressLint("WrongConstant")
    @Override
    public void onBindViewHolder(final Recycle_Threeadapter.OneViewHolder holder, int position) {
        //如果holder是EditViewHolder的实例
        View itemView = ((LinearLayout) holder.itemView).getChildAt(0);

        if (mOnItemClickListener != null) {
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = holder.getLayoutPosition();
                    mOnItemClickListener.onItemClick(holder.itemView, position );
                }
            });
        }

        String menuname = ccList.get(position).getMenuname();
        Glide.with(MyApplication.getInstance())
                .load(ccList.get(position).getPicurl())
//                .placeholder(R.drawable.im_jz)
//                .error(R.drawable.im_jz)
//                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(((OneViewHolder) holder).imageView);

        ((OneViewHolder) holder).tv.setText(menuname);


    }


    @Override
    public int getItemCount() {
        return ccList.size();
    }

    public class OneViewHolder extends RecyclerView.ViewHolder {

        TextView tv;
        ImageView imageView;

        public OneViewHolder(View itemView) {
            super(itemView);

            tv = (TextView) itemView.findViewById(R.id.time);
            imageView = (ImageView) itemView.findViewById(R.id.image);
        }
    }


}
